// 加密算法
import crypto from 'crypto-js'
const config = {
  // 注册对应服务名称
  services: {
    article: 'ARTICLE',
    behavior: 'BEHAVIOR',
    user: 'USER',
    login: 'LOGIN',
    register: 'LOGIN'
  },
  // 请求本地的请求service
  local: { user: true, article: true, behavior: true, login: true },
  // 代理前缀
  prefix: {
    server_85: '/server_85'
  },
  urls: {
    load: { url: 'api/v1/article/load/', sv: 'article' },
    loadmore: { url: 'api/v1/article/loadmore/', sv: 'article' },
    loadnew: { url: 'api/v1/article/loadnew/', sv: 'article' },
    load_article_Info: { url: 'api/v1/article/load_article_Info/', sv: 'article' },
    recommend_users: { url: 'api/v1/article/recommend_users/', sv: 'article' },
    month_hot: { url: 'api/v1/article/month_hot/', sv: 'article' },
    load_article_behavior: { url: 'api/v1/article/load_article_behavior/', sv: 'article' },
    load_article_action: { url: 'api/v1/article/load_article_action/', sv: 'article' },
    load_article_action_and_config: { url: 'api/v1/article/load_article_action_and_config/', sv: 'article' },
    load_article_comment: { url: 'api/v1/article/load_article_comment/', sv: 'article' },
    load_local_user_cloudNoteN_list: { url: 'api/v1/article/load_local_user_cloudNoteN_list/', sv: 'article' },
    load_location: { url: 'api/v1/article/load_location/', sv: 'article' },
    load_search_history: { url: 'api/v1/article/search/load_search_history/', sv: 'article' },
    del_search: { url: 'api/v1/article/search/del_search/', sv: 'article' },
    clear_search: { url: 'api/v1/article/search/clear_search/', sv: 'article' },
    associate_search: { url: 'api/v1/article/search/associate_search/', sv: 'article' },
    load_hot_keywords: { url: 'api/v1/article/search/load_hot_keywords/', sv: 'article' },
    article_search: { url: 'api/v1/article/search/article_search/', sv: 'article' },
    load_user_article_category: { url: 'api/v1/article/load_user_article_category/', sv: 'article' },
    load_category: { url: 'api/v1/article/load_category/', sv: 'article' },
    add_category: { url: 'api/v1/article/add_category/', sv: 'article' },
    delete_category: { url: 'api/v1/article/delete_category/', sv: 'article' },
    update_category: { url: 'api/v1/article/update_category/', sv: 'article' },
    load_comment_replay: { url: 'api/v1/article/load_comment_replay', sv: 'article' },
    // ==========  behavior
    public: { url: 'api/v1/behavior/public/', sv: 'behavior' },
    show_behavior: { url: 'api/v1/behavior/show_behavior/', sv: 'behavior' },
    view_article_behavior: { url: 'api/v1/behavior/view_article_behavior/', sv: 'behavior' },
    read_behavior: { url: 'api/v1/behavior/read_behavior/', sv: 'behavior' },
    forward_behavior: { url: 'api/v1/behavior/forward_behavior/', sv: 'behavior' },
    like_behavior: { url: 'api/v1/behavior/like_behavior/', sv: 'behavior' },
    share_behavior: { url: 'api/v1/behavior/share_behavior/', sv: 'behavior' },
    unlike_behavior: { url: 'api/v1/behavior/unlike_behavior/', sv: 'behavior' },
    collection_behavior: { url: 'api/v1/behavior/collection_behavior/', sv: 'behavior' },
    comment: { url: 'api/v1/behavior/comment/', sv: 'behavior' },
    // ==========  user
    user_follow: { url: 'api/v1/user/user_follow/', sv: 'user' },
    load_author: { url: 'api/v1/user/load_author/', sv: 'user' },
    load_user_info: { url: 'api/v1/usercenter/load_user_info/', sv: 'user' },
    load_user_comment: { url: 'api/v1/usercenter/load_user_comment/', sv: 'user' },
    load_user_collection: { url: 'api/v1/usercenter/load_user_collection/', sv: 'user' },
    user_fans: { url: 'api/v1/usercenter/user_fans/', sv: 'user' },
    user_center_follow: { url: 'api/v1/usercenter/user_follow/', sv: 'user' },
    user_topic: { url: 'api/v1/usercenter/user_topic/', sv: 'user' },
    update_user_info: { url: 'api/v1/usercenter/update_user_info/', sv: 'user' },
    check_nick: { url: 'api/v1/usercenter/check_nick/', sv: 'user' },
    author_material: { url: 'api/v1/author/material/upload_picture/', sv: 'user' },
    // ==========  userLV
    load_user_Lv: { url: 'api/v1/user_lv/load/lv/', sv: 'user' },
    load_user_task_desc: { url: 'api/v1/user_lv/load/task/', sv: 'user' },
    sign_in: { url: 'api/v1/user_lv/sing_in/', sv: 'user' },
    publish_experience: { url: 'api/v1/user_lv/publish/', sv: 'user' },
    comment_experience: { url: 'api/v1/user_lv/comment/', sv: 'user' },
    fabulous_experience: { url: 'api/v1/user_lv/fabulous/', sv: 'user' },
    collection_experience: { url: 'api/v1/user_lv/collection/', sv: 'user' },
    // ==========  login
    user_login: { url: 'api/v1/login/login_auth/', sv: 'login' },
    // ==========  register
    register_auth: { url: 'api/v1/register/register_auth/', sv: 'login' },
    get_image_verify_code: { url: 'api/v1/register/get_image_verify_code/', sv: 'login' },
    get_active_code: { url: 'api/v1/sms_code/active_code', sv: 'login' },
    // 解决多访问地址的问题
    getBase: function (url) {
      const sv = url.sv
      // 默认指向85服务器，并指向网关+服务名；否则走本地，不加服务名
      if (config.local[sv]) {
        return '/' + sv
      } else {
        return config.prefix.server_85 + '/' + config.services[sv]
      }
    },
    get: function (name) {
      const tmp = config.urls[name]
      if (tmp) { return config.urls.getBase(tmp) + '/' + tmp.url } else { return name }
    }
  },
  sign: function (parms) {
    const arr = []
    for (var key in parms) {
      arr.push(key)
    }
    arr.sort()
    let str = ''
    for (var i in arr) {
      if (str !== '') {
        str += '&'
      }
      str += arr[i] + '=' + parms[arr[i]]
    }
    // console.log(parms)
    // console.log(crypto.MD5(str).toString())
    return crypto.MD5(str).toString()
  }
}
export default config
